﻿ <%--
  *  File:    ZylCustomerCollateEdit.jsp
  *  @Author: Rogerwang
  *  Date:    2006/4/25
  *
  *  Copyright (C) 2000 - 2005 Oval Technologies, Inc.
  *  All rights reserved.
  *
  *  This software is the confidential and proprietary information of Oval
  *  Technologies, Inc. ("Confidential Information").  You shall not
  *  disclose such Confidential Information and shall use it only in
  *  accordance with the terms of the license agreement you entered into
  *  with Oval.
 --%>

<%@ page contentType = "text/html;charset=UTF-8" %>

 <%
   //init param
   Category cat = Category.getInstance("jsp.ZylCustomerCollateEdit");
   String strTableName = "v_customercollateedit";
   String strModuleName = "COM";
   String privilegeCode = "A0701";
     String contextPath = request.getContextPath();
 %>
        <%@ include file="/inc/CommonHeader.inc" %>
        <%@ include file="/inc/OvalLocationDefault.inc" %>
		<%@ include file="/inc/Print.inc"%>
		<%@ include file="/rpt/ReportURL.inc" %>
 <%
   //get curuser info
   HashMap CurUserInfo = (HashMap)session.getAttribute("userinfo");
   String strCurOrgName = (String)CurUserInfo.get("orgname");
   Integer nCurOrgId = (Integer)CurUserInfo.get("orgid");
   Integer nCurUserId = (Integer)CurUserInfo.get("userid");
   String  isadmin=(String)CurUserInfo.get("isadmin");
   if(nCurOrgId == null)
   {
     nCurOrgId = new Integer(-1234567);
   }
 %>

 <html>
 <head>
 <title>ZylCustomerCollateEdit</title>
 <PageFlow:CheckPageFlow pageName="p_zylcustomercollateedit"/>
 <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
 <%@ include file="/inc/CatchError.inc" %>
 <script language="JavaScript" src="<%=contextPath %>/js/ScriptLib.js"></script>
 <script language="JavaScript" src="<%=contextPath %>/js/SummaryDivision.js"></script>
 <link rel="stylesheet" href="<%=contextPath %>/css/<%= strLanguageCode %>/main.css" type="text/css">
 <script language="JavaScript" src="<%=contextPath %>/css/<%= strLanguageCode %>/script.js"></script>
 <script language="JavaScript" src="<%=contextPath %>/js/Calendar.js"></script>
<script language="JavaScript" src="<%=contextPath %>/js/FuncLib.js"></script>
<script language="JavaScript" src="<%=contextPath %>/js/opal2/mootools.js"></script>
 <%@ include file="/inc/SummaryDivision.inc" %>
 <%
   Vector totalsummary = (Vector)pageContext.getAttribute("totalsummary");
   if(totalsummary == null)
   {
     totalsummary = new Vector();
   }
   
	String orgoptionvalue = (String)pageContext.getAttribute("orgoption");
	if(orgoptionvalue == null)orgoptionvalue = "1";
 %>
 <script>
 var popwindow;
 function page_summary(actionvalue,orderbyname)
 {
     if(isEmpty(cform.keyname.value) && false)
     {
         alert("<%= message.getMessageDesc("VALUE_NOT_NULL",label.getLabelName("L_CustomerKey"))%>");
         return;
     }

   var editform = summaryPrepare(cform,actionvalue,orderbyname);
   editform.action = "ZylCustomerCollateEdit.jsp?<%= OvalTools.randomURL() %>&flag=y";
   editform.target = "_self";
   isRunning = true;
   editform.submit();
 }


 function checkAll()
 {
      if(cform.selorgids)
      {
         if(cform.selorgids.length)
         {
             for(var i=0;i<cform.selorgids.length;i++)
             {

                  cform.selorgids[i].checked=cform.selectall.checked;
             }
         }else
         {
             cform.selorgids.checked=cform.selectall.checked;
         }


      }
 }
 function page_update()
 {
  
  var flag = confirm("<%= message.getMessageDesc("ARE_YOU_SURE_TO_UPDATE") %>");
    if(!flag)
  return;
  document.cform.action = "ZylCustomerCollateEdit.jsp?<%= OvalTools.randomURL() %>&flag=u";
   document.cform.target = "_self";
   isRunning = true;
   document.cform.submit();
   alert("已修改完成！");
 }
 
 function page_go()
 {
     if(isNullChecked(cform.selorgids)==true)
   {
       alert("<%= message.getMessageDesc("PLEASE_SELECT") %>");
       return;
   }
    if(isEmpty(cform.orgid.value))
     {
         alert("<%= message.getMessageDesc("VALUE_NOT_NULL",label.getLabelName("L_CustomerCollateCode"))%>");
         return;
    }
   var flag = confirm("<%= message.getMessageDesc("ARE_YOU_SURE") %>");
   if(!flag)
     return;

 <%--emptyToNull(document.cform);--%>
   document.cform.action = "ZylCustomerCollateEdit.jsp?<%= OvalTools.randomURL() %>&flag=s";
   document.cform.target = "_self";
   document.cform.pageaction.value = "OrderBy";
   isRunning = true;
   document.cform.submit();
 }
 
 function page_pretreatment()
 {
   document.cform.action = "ZylCustomerCollateEdit.jsp?<%= OvalTools.randomURL() %>&flag=d";
   document.cform.target = "_self";
   document.cform.pageaction.value = "OrderBy";
   isRunning = true;
   document.cform.submit();
 }

 var type;

 function page_selectProvince(obj)
 {
   type=obj;
   if(popwindow!=null)
    popwindow.close();
   popwindow = window.open('<%=contextPath %>/masterdata/ogm/RegionSelect.jsp?<%= OvalTools.randomURL() %>&languagecode=<%= strLanguageCode %>&countrycode=CN','newwindow', 'height=250, width=500,top=100,left=100,toolbar=n0, menubar=no, scrollbars=no, resizable=no, location=no, status=no');
 }

 function page_setRegion(code,name)
 {
	 var regioncode;
     var regionname;
     var citycode;
     var cityname;
	 var countycode;
	 var countyname;
     if(type=='customer'){
		 regioncode=eval('document.cform.regioncode');
         regionname=eval('document.cform.regionname');
         citycode=eval('document.cform.citycode');
         cityname=eval('document.cform.cityname');
     }else if(type=='newcustomer'){
		 regioncode=eval('document.cform.newregioncode');
         regionname=eval('document.cform.newregionname');
         citycode=eval('document.cform.newcitycode');
         cityname=eval('document.cform.newcityname');
		 countycode = eval('document.cform.newcountycode');
		 countyname = eval('document.cform.newcountyname');
     } else{
		 regioncode=eval('document.cform.sregioncode');
         regionname=eval('document.cform.sregionname');
         citycode=eval('document.cform.scitycode');
         cityname=eval('document.cform.scityname');
     }

     if(code != regioncode.value && type=='newcustomer'){
         citycode.value='';
         cityname.value='';
		 countycode.value='';
         countyname.value='';
     }else{
		 citycode.value='';
         cityname.value='';
	 }
   regioncode.value = code;
   regionname.value = name;
   if(type!='newcustomer'){
	cform.newsregioncode.value = code;
	cform.newsregionname.value = name;
   }
   if (popwindow != null)
     popwindow.close();
 }

 function page_selectCity(obj,flag,grade)
 {
	 var proidstring = document.cform.proid.value;
     var sregioncode = document.cform.sregioncode.value;
	 var sregionname = document.cform.sregionname.value;
     type=obj;
      var regioncode;
     if(type=='customer')
     {
         regioncode=eval('document.cform.regioncode');
     }
     else
     {
         regioncode=eval('document.cform.sregioncode');
     }
   if(isEmpty(regioncode.value))
   {
     alert("<%= message.getMessageDesc("MUST_SELECT_FIRST",label.getLabelName("L_Province"))%>");
     return;
   }
   if(popwindow!=null)
     popwindow.close();
   popwindow = window.open('<%=contextPath %>/masterdata/ogm/CitySelect.jsp?<%= OvalTools.randomURL() %>&languagecode=<%= strLanguageCode %>&countrycode=CN' + '&regioncode=' + regioncode.value +'&proidstring='+proidstring + '&flag=' + flag+'&grade='+grade,'newwindow', 'height=250, width=400,top=100,left=100,toolbar=n0, menubar=no, scrollbars=yes, resizable=no, location=no, status=no');
 }

 function page_setCity(code,name,id,flag)
 {
     if(type=='newcustomer'){
		page_setCity1(code,name,id,flag);
		return;
	 }
	 var citycode;
     var cityname;
     if(type=='customer'){
         citycode=eval('document.cform.citycode');
         cityname=eval('document.cform.cityname');
     }else{
         citycode=eval('document.cform.scitycode');
         cityname=eval('document.cform.scityname');
     }
   citycode.value = code;
   cityname.value = name;
   if(type!='newcustomer'){
	cform.newscitycode.value = code;
	cform.newscityname.value = name;
   }
   if (popwindow != null)
     popwindow.close();
 }
 function page_setCity1(code,name,id,flag)
{
	if(flag == "county"){
		document.cform.newcountycode.value = code;
		document.cform.newcountyname.value = name;
	}else {
		document.cform.newcitycode.value = code;
		document.cform.newcityname.value = name;
		document.cform.newcountycode.value = " ";
    	document.cform.newcountyname.value = " ";
	}
  if (popwindow != null)
    popwindow.close();
}

function page_selectCity1(obj,flag,grade)
{
  type=obj;
  var regioncode = document.cform.newregioncode.value;
  var parentcitycode = document.cform.newcitycode.value;
  if(flag=="city")parentcitycode='null';
  if(regioncode=="" || regioncode==-1)
  {
    alert("<%= message.getMessageDesc("MUST_SELECT_FIRST",label.getLabelName("L_Province"))%>");
    return;
    if(parentcitycode=="" || parentcitycode==-1)
  {
    alert("<%= message.getMessageDesc("MUST_SELECT_FIRST",label.getLabelName("L_City"))%>");
    return;
  }
  }
  
  if(popwindow!=null)
    popwindow.close();
  popwindow = window.open('<%=contextPath %>/masterdata/ogm/CitySelect.jsp?<%= OvalTools.randomURL() %>&languagecode=<%= strLanguageCode %>&countrycode=CN&regioncode=' + regioncode + '&flag=' + flag+'&grade='+grade+'&parentcitycode='+parentcitycode,'newwindow', 'height=250, width=400,top=100,left=100,toolbar=n0, menubar=no, scrollbars=yes, resizable=no, location=no, status=no');
}

 function page_changeRegion(obj)
 {
	var regioncode = cform.newsregioncode.value;
	page_cleanregionandcity();
	if(regioncode == "")return;
    var datahandler = new  DataHandler() ;
    datahandler.add_params("regioncode" , regioncode, 'String') ;
    datahandler.add_params("languagecode" , document.cform.languagecode.value, 'String') ;
    datahandler.getResult("regioncode" ,"document.cform.sregioncode");
    datahandler.getResult("regioncode" ,"document.cform.newsregioncode");
    datahandler.getResult("regionname" ,"document.cform.newsregionname");
    datahandler.getResult("regionname" ,"document.cform.sregionname");
    datahandler.add_job("j_getregionbycode");
    datahandler.runDataHandler();
 }

function page_checkRegion(){
	if(cform.sregioncode.value == ""){
		cform.newsregioncode.value = "";
	}
}
 
 function page_changeCity(obj)
 {
	var regioncode = cform.newsregioncode.value;
	var citycode = cform.newscitycode.value;
	if(isEmpty(regioncode))
	{
	  alert("<%= message.getMessageDesc("MUST_SELECT_FIRST",label.getLabelName("L_Province"))%>");
	  return;
	}
	page_cleancity();
	if(regioncode == "")return;
	var datahandler = new  DataHandler() ;
	datahandler.add_params("regioncode" , regioncode, 'String') ;
	datahandler.add_params("citycode" , citycode, 'String') ;
	datahandler.add_params("languagecode" , document.cform.languagecode.value, 'String') ;
	datahandler.getResult("citycode" ,"document.cform.scitycode");
	datahandler.getResult("citycode" ,"document.cform.newscitycode");
	datahandler.getResult("cityname" ,"document.cform.newscityname");
	datahandler.getResult("cityname" ,"document.cform.scityname");
	datahandler.add_job("j_getcitybycode");
	datahandler.runDataHandler();
 }
 
function page_cleanregionandcity(){
	cform.sregioncode.value = "";
	cform.newsregioncode.value = "";
	cform.sregionname.value = "";
	cform.newsregionname.value = "";
	cform.scitycode.value = "";
	cform.newscitycode.value = "";
	cform.scityname.value = "";
	cform.newscityname.value = "";
}

function page_cleancity(){
	cform.scitycode.value = "";
	cform.newscitycode.value = "";
	cform.scityname.value = "";
	cform.newscityname.value = "";
}
 function page_selectCustomer()
 {
    window.open("<%=contextPath%>/masterdata/ogm/OrgSelect.jsp?<%= OvalTools.randomURL() %>", "newwindow", "height=450, width=600,top=100,left=100,toolbar=n0, menubar=no, scrollbars=yes, resizable=no, location=no, status=no")
 }
 function page_setOrg(orgid,orgname,orgcode)
 {
    document.cform.orgid.value=orgid;
    document.cform.orgname.value=orgname;
    document.cform.orgcode.value=orgcode;
	hiddenFrm();
 }

 function page_reload()
{
   document.cform.orgid.value="";
   document.cform.orgname.value="";
   if(isEmpty(document.cform.orgcode.value))
   {
        document.cform.orgcode.value = "";
        return;
   }
    var  datahandler = new  DataHandler() ;
    datahandler.add_params("selectoption" , "xjpcustomer") ;
    datahandler.add_params("searchname" , "orgcode") ;
    datahandler.add_params("searchvalue" , document.cform.orgcode.value) ;
    datahandler.getResultFromHashMap("orgsummary" ,"orgcode" ,"document.cform.orgcode");
    datahandler.getResultFromHashMap("orgsummary" ,"orgid" ,"document.cform.orgid");
    datahandler.getResultFromHashMap("orgsummary" ,"orgname" ,"document.cform.orgname");
    datahandler.add_job("getrelatedorg") ;
	datahandler.add_function("page_checkOrg()");
    datahandler.runDataHandler ();
}

function page_checkOrg(){
	if(cform.orgid.value == ""){
		cform.orgcode.value = "";
	}
}
 
 function setNewRegionCode(newareacode,areaname,regioncode){
        var length = newareacode.length;
	    var regioncodearray= regioncode;
	    var areanamearray=areaname;
		var areaidString = "";
		var areanameString = "";
		var regioncodeString = "";
		var StrsRegioncode = "";
	   	var StrsRegionname = "";
	  for(var i = 0;i < length;i++){
			if(i == length - 1){
				areaidString = areaidString + newareacode[i].value;
				areanameString = areanameString + "'" + areanamearray[i].value + "'";
				regioncodeString = regioncodeString + "'" + regioncodearray[i].value + "'";
				
				StrsRegionname = StrsRegionname + areanamearray[i].value;
			    StrsRegioncode = StrsRegioncode + regioncodearray[i].value;
			}else{
				areaidString = areaidString + newareacode[i].value + ",";				
				areanameString = areanameString + "'" + areanamearray[i].value + "'" + ",";
				regioncodeString = regioncodeString + "'" +regioncodearray[i].value + "'" + ",";
				
				StrsRegionname = StrsRegionname + areanamearray[i].value + ",";
				StrsRegioncode = StrsRegioncode +regioncodearray[i].value + ",";
			}			
		} 
		cform.sregionname.value = "";
		cform.sregionname.value = areanameString;
		cform.scityname.value = "";
		cform.proid.value = "";
		cform.proid.value = areaidString;
		cform.sregioncode.value = "";
		cform.sregioncode.value = regioncodeString;
		
		cform.newsregionname.value = "";
	    cform.newsregionname.value = StrsRegionname;
		cform.newsregioncode.value = "";
		cform.newsregioncode.value = StrsRegioncode;
 }
		
 function setNewCityCode(newareacode,areaname,citycodeinfo){
	  var length = newareacode.length;
	  var citycodearray=citycodeinfo;
	  var areanamearray=areaname;
		var areaidString = "";
		var areanameString = "";
		var citycodeString = "";
		var StrsCitycode = "";
	   	var StrsCityname = "";
		for(var i = 0;i < length;i++){
			if(i == length - 1){
				areaidString = areaidString + newareacode[i].value;
				areanameString = areanameString + "'" + areanamearray[i].value + "'";
				citycodeString = citycodeString + "'" + citycodearray[i].value + "'";
				
				StrsCityname = StrsCityname + areanamearray[i].value;
				StrsCitycode = StrsCitycode + citycodearray[i].value;
			}else{
				areaidString = areaidString + newareacode[i].value + ",";
				areanameString = areanameString + "'" + areanamearray[i].value + "'" + ",";
				citycodeString = citycodeString + "'" + citycodearray[i].value + "'" + ",";
				
				StrsCityname = StrsCityname + areanamearray[i].value + ",";
			    StrsCitycode = StrsCitycode + citycodearray[i].value + ","; 
			}			
		}
		cform.scityname.value = "";
		cform.scityname.value = areanameString;
		cform.cityid.value = "";
		cform.cityid.value = areaidString;
		cform.scitycode.value = "";
		cform.scitycode.value = citycodeString;
		
		cform.newscityname.value = "";
		cform.newscityname.value = StrsCityname;
		cform.newscitycode.value = "";
		cform.newscitycode.value = StrsCitycode;
 }

function page_upload(){
		this.location.href = "<%= contextPath%>/phap/masterdata/spm/UploadEXL.jsp?first=ZZ&second=ZB01&third=Z0608&<%= OvalTools.randomURL() %>";
}

function page_excelload(){

		regionid= document.cform.regionid.value;
	
	    if(regionid !=""){
	 	 window.location.href = "<%= reportURL %>/servlet/ExcecuteReport/TerminalMasterDataDownLoad.sox?__folder=/ovalreport&rownum=2&regionid="+regionid;	
	   }else{
	   window.location.href = "<%= reportURL %>/servlet/ExcecuteReport/TerminalMasterDataDownLoad.sox?__folder=/ovalreport&rownum=2";	
	     }
 }

var popwindow;
function page_initDiv(){
	document.cform.neworgcode.value="";
    document.cform.neworgname.value="";
    document.cform.newregioncode.value="";
    document.cform.newregionname.value="";
    document.cform.newcitycode.value="";
    document.cform.newcityname.value="";
    document.cform.newcountycode.value="";
    document.cform.newcountyname.value="";
    document.cform.lorgid.value="";
	document.cform.lorgname.value="";
	document.cform.newxorgid.value="";
}
function subDiv(n) {
    neworgcode = document.cform.neworgcode.value;
    neworgname = document.cform.neworgname.value;
    regioncode = document.cform.newregioncode.value;
    citycode = document.cform.newcitycode.value;
    countycode = document.cform.newcountycode.value;
    regionname = document.cform.newregionname.value;
    cityname = document.cform.newcityname.value;
    countyname = document.cform.newcountyname.value;
    globalpccode = document.cform.globalpccode.value;
	neworgid = document.cform.neworgid.value;	
	
	var lorgid = document.cform.lorgid.value;
	var lorgname = document.cform.lorgname.value;
	var newxorgid = document.cform.newxorgid.value;
    if(n!=1){
		if(!checkForm(document.cform))return;
	}
    var  datahandler = new  DataHandler();
	datahandler.add_params("neworgid" , neworgid, 'Integer');
	datahandler.add_params("neworgcode" , neworgcode, 'String');
	datahandler.add_params("neworgname" , escape(encodeURI(neworgname)), 'String');
	datahandler.add_params("regioncode" , regioncode, 'String');
	datahandler.add_params("citycode" , citycode, 'String');
	datahandler.add_params("countycode" , countycode, 'String');
	datahandler.add_params("regionname" , escape(encodeURI(regionname)), 'String');
	datahandler.add_params("cityname" , escape(encodeURI(cityname)), 'String');
	datahandler.add_params("countyname" , escape(encodeURI(countyname)), 'String');
	datahandler.add_params("globalpccode" , globalpccode, 'String');
	if(parseInt(lorgid) != parseInt(newxorgid)){
		datahandler.add_params("lorgid" , lorgid, 'Integer');
		datahandler.add_params("lorgname" , escape(encodeURI(lorgname)), 'String');
		datahandler.add_params("newxorgid" , newxorgid, 'Integer');
	}
	
	datahandler.getResultFromHashMap("errorhash" ,"messagecode" ,"document.cform.messagecode");
	datahandler.getResultFromHashMap("errorhash" ,"s1" ,"document.cform.s1");
	datahandler.add_job("j_zylmodifynolock");
	datahandler.runDataHandler();
	setTimeout("page_outTheError();","500");
}
var trindex=-1;
function page_outTheError(){
	messagecode = document.cform.messagecode.value;
	s1 = document.cform.s1.value;
	if(messagecode=="P_Not_Same"){
		alert(s1+"在系统内有重复，请重新输入！");
		return;
	}
	page_changeTabelHtml(trindex);
	hidDiv("submit");
}

function page_changeTabelHtml(m){
	neworgcode = document.cform.neworgcode.value;
    neworgname = document.cform.neworgname.value;
    newregionname = document.cform.newregionname.value;
    newcityname = document.cform.newcityname.value;
    
    
    newcountyname = document.cform.newcountyname.value;
    
	document.getElementById("tr" +m).cells[8].innerHTML = neworgcode + "&nbsp;"+neworgname;
	document.getElementById("tr" +m).cells[5].innerHTML = newregionname + "&nbsp;";
	document.getElementById("tr" +m).cells[6].innerHTML = newcityname + "&nbsp;";
	document.getElementById("tr" +m).cells[7].innerHTML = newcountyname + "&nbsp;";
	
}

function showDiv(element,strcode,strname,strregioncode,strcitycode,strcountycode,strregionname,strcityname,strcountyname,strorgcolid,newxorgid,num) {
	trindex = num;
	var W = document.documentElement.scrollWidth;
    var H = document.documentElement.scrollHeight;
    var selfW = document.getElementById(element).style.width;
    var selfH = document.getElementById(element).style.height;
    document.getElementById(element).style.left = (W - parseInt(selfW)) / 2 + 'px';
    document.getElementById(element).style.top = (H - parseInt(selfH)) / 2 + 'px';
	//document.cform.neworgid.value=strorgid;
	document.cform.neworgid.value=strorgcolid;
	document.cform.neworgcode.value=strcode;
    document.cform.neworgname.value=strname;
    document.cform.newregioncode.value=strregioncode;
    document.cform.newcitycode.value=strcitycode;
    document.cform.newcountycode.value=strcountycode;
    document.cform.newregionname.value=strregionname;
    document.cform.newcityname.value=strcityname;
    document.cform.newcountyname.value=strcountyname;
    
    document.cform.newxorgid.value=newxorgid;
    
    document.cform.lorgid.value=newxorgid;
    document.cform.lorgname.value=strname;
    document.getElementById(element).style.display = 'block';
    var mDiv = document.getElementById("mDiv");
    mDiv.style.display = '';
    document.cform.subbutton.focus();
}

function hidDiv(element) {
    document.getElementById(element).style.display = 'none';
    document.getElementById("mDiv").style.display = 'none';
    page_initDiv();
}

var isHidden;
function frm_select(e){
	isHidden = "block";
	var _target = getPosition(e);
    var _obj = document.getElementById("summaryfrm");
    _obj.style.left = _target.x;
    _obj.style.top = _target.y + e.clientHeight ;
    _obj.style.height="250px";
    _obj.style.width="650px";
    _obj.style.zIndex = 5000;
    _obj.style.display = "block";
}

function getPosition(e) {
        var left = 0;
        var top = 0;
        while (e.offsetParent) {
            left += e.offsetLeft + (e.curentStyle? (parseInt(e.curentStyle.borderLeftWidth).NaN0()):0);
            top += e.offsetTop + (e.curentStyle ? (parseInt(e.curentStyle.borderTopWidth)).NaN0() : 0);
            e = e.offsetParent;
        }
        left += e.offsetLeft + (e.curentStyle ? (parseInt(e.curentStyle.borderLeftWidth)).NaN0() : 0);
        top += e.offsetTop + (e.curentStyle ? (parseInt(e.curentStyle.borderTopWidth)).NaN0() : 0);
        return {x:left, y:top};
}
function closeItemSelect(evt)
{
	var _obj = document.getElementById("summaryfrm");
	if(isHidden == "block"){
		isHidden = "none";
	}else{
		_obj.style.display = "none";
	}
	evt = evt || window.event;
        var _target = evt.target || evt.srcElement;
        if (!_target.getAttribute("Author") && _target != inputObj && _target != targetObj) {
            getObjById("Calendar").style.display = "none";
            getObjById("CalendarFrm").style.display = "none";
        }
}

function hiddenFrm(){
	document.getElementById("summaryfrm").style.display = "none";
}

document.onclick=closeItemSelect; 

function page_download(){
	var url;
	var searchStr="";
	var searchStrValue = "";
	var searchname = cform.searchnamealias.options[cform.searchnamealias.selectedIndex].value;
	var searchvalue =cform.searchvalue.value;
	if(searchvalue==""||searchvalue==null)searchStr=null;
	var searchnamevalue = searchname.substring(0,searchname.indexOf("^"));
	if(searchnamevalue == "statusname") seachStrValue="e.valuename";
	if(searchnamevalue == "custcolcode") seachStrValue="b.orgcode";
	if(searchnamevalue == "dealername") seachStrValue="c.orgname";
	if(searchnamevalue == "dealercode") seachStrValue="c.orgcode";
	searchStr = "and "+seachStrValue+" like '"+searchvalue+"'";
	var inorgname =cform.keyname.value;
	var notinorgname = cform.keynameexc.value;
	var areaids = cform.areaids.value;
	/* var areacodeid = cform.regionid.options[cform.regionid.selectedIndex].value;
	if(areacodeid==""||areacodeid==null)
	{
		alert("请选择您所在的大区");
		return;
	}
	*/
	var regioncode = cform.newsregioncode.value;
	var citycode = cform.newscitycode.value;
	var checked = document.getElementsByName("clstflag");
	if(!checked[1].checked){
		alert("必须选中未对照上的客户列表");
		return;
	}
	url= "<%=reportURL%>"+"/servlet/ExcecuteReport/NonLockCustomerCollate.sox?__format=xlsx&__folder=/ovalreport&<%= OvalTools.randomURL() %>&employeeid=<%=nCurUserId%>&areaids="+areaids; 
	if(!isEmpty(searchvalue)) url += "&searchnamevalue=" + escape(encodeURI(searchStr));
	if(!isEmpty(inorgname)) url += "&inorgname=" + escape(encodeURI(inorgname));
	if(!isEmpty(notinorgname)) url += "&notinorgname=" + escape(encodeURI(notinorgname));
	if(!isEmpty(areacodeid)) url += "&areacodeid=" + escape(encodeURI(areacodeid));
	if(!isEmpty(regioncode)) url += "&regioncode=" + escape(encodeURI(regioncode));
	var style = "height=600, width=900, top=50, left=120, toolbar=no, menubar=no, scrollbars=no, resizable=no,location=no, status=no";
	window.open (url, 'newwindow', style);
}
function page_uploadModify(){
	var url;
	var searchStr="";
	var searchStrValue = "";
	var searchname = cform.searchnamealias.options[cform.searchnamealias.selectedIndex].value;
	var searchvalue =cform.searchvalue.value;
	if(searchvalue==""||searchvalue==null)searchStr=null;
	var searchnamevalue = searchname.substring(0,searchname.indexOf("^"));
	if(searchnamevalue == "statusname") seachStrValue="e.valuename";
	if(searchnamevalue == "custcolcode") seachStrValue="b.orgcode";
	if(searchnamevalue == "dealername") seachStrValue="c.orgname";
	if(searchnamevalue == "dealercode") seachStrValue="c.orgcode";
	searchStr = "and "+seachStrValue+" like '"+searchvalue+"'";
	var inorgname =cform.keyname.value;
	var notinorgname = cform.keynameexc.value;
	var areaids = cform.areaids.value;
	/* var areacodeid = cform.regionid.options[cform.regionid.selectedIndex].value;
	if(areacodeid==""||areacodeid==null)
	{
		alert("请选择您所在的大区");
		return;
	}
	*/
	var regioncode = cform.newsregioncode.value;
	var citycode = cform.newscitycode.value;
	var checked = document.getElementsByName("clstflag");
	if(!checked[0].checked){
		alert("请选择所有客户列表");
		return;
	}
	<%if("Y".equals(isadmin)){%>
	url= "<%=reportURL%>"+"/servlet/ExcecuteReport/CustomerCollateModify.sox?__format=xlsx&__folder=/ovalreport&<%= OvalTools.randomURL() %>&areaids="+areaids; 
	 <%}else{%>
	 	 url= "<%=reportURL%>"+"/servlet/ExcecuteReport/CustomerCollateModify.sox?__format=xlsx&__folder=/ovalreport&<%= OvalTools.randomURL() %>&employeeid=<%=nCurUserId%>&areaids="+areaids; 
	 <%}%>
	if(!isEmpty(searchvalue)) url += "&searchnamevalue=" + escape(encodeURI(searchStr));
	if(!isEmpty(inorgname)) url += "&inorgname=" + escape(encodeURI(inorgname));
	if(!isEmpty(notinorgname)) url += "&notinorgname=" + escape(encodeURI(notinorgname));
	//if(!isEmpty(areacodeid)) url += "&areacodeid=" + escape(encodeURI(areacodeid));
	if(!isEmpty(regioncode)) url += "&regioncode=" + escape(encodeURI(regioncode));
	var style = "height=600, width=900, top=50, left=120, toolbar=no, menubar=no, scrollbars=no, resizable=no,location=no, status=no";
	window.open (url, 'newwindow', style);
}
function page_uploadModify2(){
	var url;
	var searchStr="";
	var searchStrValue = "";
	var searchname = cform.searchnamealias.options[cform.searchnamealias.selectedIndex].value;
	var searchvalue =cform.searchvalue.value;
	if(searchvalue==""||searchvalue==null)searchStr=null;
	var searchnamevalue = searchname.substring(0,searchname.indexOf("^"));
	if(searchnamevalue == "statusname") seachStrValue="e.valuename";
	if(searchnamevalue == "custcolcode") seachStrValue="b.orgcode";
	if(searchnamevalue == "dealername") seachStrValue="c.orgname";
	if(searchnamevalue == "dealercode") seachStrValue="c.orgcode";
	searchStr = "and "+seachStrValue+" like '"+searchvalue+"'";
	var inorgname =cform.keyname.value;
	var notinorgname = cform.keynameexc.value;
	var areaids = cform.areaids.value;
	/* var areacodeid = cform.regionid.options[cform.regionid.selectedIndex].value;
	if(areacodeid==""||areacodeid==null)
	{
		alert("请选择您所在的大区");
		return;
	}
	*/
	var regioncode = cform.newsregioncode.value;
	var citycode = cform.newscitycode.value;
	
	url= "<%=reportURL%>"+"/servlet/ExcecuteReport/CustomerCollateModify2.sox?__format=xlsx&__folder=/ovalreport&<%= OvalTools.randomURL() %>&employeeid=<%=nCurUserId%>&areaids="+areaids; 
	if(!isEmpty(searchvalue)) url += "&searchnamevalue=" + escape(encodeURI(searchStr));
	if(!isEmpty(inorgname)) url += "&inorgname=" + escape(encodeURI(inorgname));
	if(!isEmpty(notinorgname)) url += "&notinorgname=" + escape(encodeURI(notinorgname));
	//if(!isEmpty(areacodeid)) url += "&areacodeid=" + escape(encodeURI(areacodeid));
	if(!isEmpty(regioncode)) url += "&regioncode=" + escape(encodeURI(regioncode));
	var style = "height=600, width=900, top=50, left=120, toolbar=no, menubar=no, scrollbars=no, resizable=no,location=no, status=no";
	window.open (url, 'newwindow', style);
}
function popBusinessarea_moulty(){
	if(popwindow!=null) popwindow.close();
	
    url = '<%=contextPath %>/phap/phap.datp/masterdata/cm/dataclean/ZylStdareaSelect.jsp?<%= OvalTools.randomURL() %>';
    attribute = 'height=500, width=900,top=100,left=100,toolbar=no, menubar=no, scrollbars=yes, resizable=no, location=no, status=no';
	popwindow = window.open(url,'newwindow', attribute);
}

function setAreas(areaids,areanames,areacodes){

	document.cform.areaids.value = areaids;
	document.cform.businessareaname.value = areanames;
	//document.cform.businessareacode.value = areacodes;
} 
function page_upload(){
	this.location.href = "<%= contextPath%>/zyl/dataclean/ZylUploadCustomerCollate.jsp?&<%= OvalTools.randomURL() %>";
}

function OrgSelectPop(obj)
{
  type=obj;
  if(popwindow!=null)
   popwindow.close();
  popwindow = window.open('<%=contextPath %>/tdr/dataconfirm/PathOrgSelect.jsp?maxitem=8&globalpccode=100&<%= OvalTools.randomURL() %>&languagecode=<%= strLanguageCode %>','newwindow', 'height=250, width=500,top=100,left=100,toolbar=n0, menubar=no, scrollbars=no, resizable=no, location=no, status=no');
}
function page_setOrg(id, name, code)
{
	eval('document.cform.newxorgid').value = id;
	eval('document.cform.neworgcode').value = code;
	eval('document.cform.neworgname').value = name;
	if (popwindow != null){
	    popwindow.close();
	}
}
 </script>
 </head>
 <body leftmargin="0" topmargin="0" marginwidth="0" marginheight="0">
 <iframe name="summaryfrm" scrolling="yes" frameborder="0" style="position:absolute; top:0px; left:0px; display:none;border:#909eff 1px solid;"></iframe>
 <iframe id="reloadHandler" name="reloadHandler" style="display:none"></iframe>
  <form name="cform" method="post" action="<%=contextPath %>/Dispatcher">
       <input type="hidden" name="pagename" value="p_zylcustomercollateedit">
       <input type="hidden" name="actionname"/>
	   <input type="hidden" name="name" value="">
  	   <input type="hidden" name="type" value="">
  	   <input type="hidden" name="clstflagvalue" value="">
  	   <custom:hidden property="proid"/>
	   <custom:hidden property="cityid"/>
       <custom:hidden property="sregioncode"/>
       <custom:hidden property="sregionname"/>
       <custom:hidden property="scitycode"/>
       <custom:hidden property="scityname"/>
       <custom:hidden property="messagecode"/>
       <custom:hidden property="s1"/>
       <custom:hidden property="languagecode" scope="session"/>
	   <custom:hidden name="userinfo" property="userid" scope="session"/>
	   <custom:hidden property="orgids"/>
 <%--  page location   --%>
   <%@ include file="/inc/PageLocation.inc" %>

     <table width="100%" cellspacing="0" cellpadding="0" border="0" onkeydown="if(event.keyCode==13) page_summary('search');">

         <tr>
             <td width="80%">
                 <table  width="100%" cellspacing="0" cellpadding="0" border="0"  >
                       <tr>
                         <td  align="right" width="120">
                             <font color=black><%= label.getLabelName("L_CustomerKey") + label.getLabelName("L_Colon") %></font>
                         </td>
                         <td>
                             <custom:text property="keyname"  size="15"/>
                         </td>
						 <td align="right" width="100">
                             <%= label.getLabelName("L_KeyExclude") + label.getLabelName("L_Colon") %>
                         </td>
                         <td>
                             <custom:text property="keynameexc" size="15"/>
                         </td>
                         <td style="width:60px;" class="td_right">
						<%=label.getLabelName("L_Provicetdr") +  label.getLabelName("L_Colon") %>
						 </td>
						  <td style="width:160px;" class="td_left"> <custom:hidden  property="areaids" />
					<custom:text  property="businessareaname"  label="L_Provicetdr" readonly="true"/>
					<a onclick="popBusinessarea_moulty()"><custom:button type="3" value="*"/></a>
						
		           </td>
						 <%
                                String clstflag = (String)pageContext.getAttribute("clstflag");
                                if(clstflag==null){
                                    clstflag="N";
                                }
                         %>
                       </tr>
<%-----------------------第二行---------------------%>
                       <tr>
                       <td align="right" width="120"><%= label.getLabelName(" L_DealerProvince") + label.getLabelName("L_Colon") %>
                         </td>
                         <td>
                             <custom:text property="newsregioncode"  size="15" onchange="page_changeRegion('supplier')"/>
                             <a onclick="javascript:page_selectProvince('supplier');"><custom:button type="3" label="L_Asterisk" imgsrc="flash.gif" border="0"/></a>
                             <custom:text property="newsregionname" size="20" readonly="true"/>
                         </td>
                         <td align="right" width="100">
                             <%= label.getLabelName(" L_DealerCity") + label.getLabelName("L_Colon") %>
                          </td>
                         <td>
                             <custom:text property="newscitycode"   size="15" onchange="page_changeCity('supplier')"/>
                             <a onclick="javascript:page_selectCity('supplier','city',1);"><custom:button type="3" label="L_Asterisk" imgsrc="flash.gif" border="0"/></a>
                             <custom:text property="newscityname"   size="20" readonly="true" />
                         </td>
                       </tr>
                 </table>
                 <table>
						  <%@ include file="/inc/SummarySearch.inc" %>
                 </table>
              </td>
             <td width="20%">
             	<table>
					<tr>
						<td>
							<input name="clstflag" type="radio" class="normalradio" value="A" <%=clstflag.equalsIgnoreCase("A")?"checked":""%> checked="true">
							<%= label.getLabelName(" L_AllCustomerList") %>
						</td>
						<td>&nbsp;</td>             	
					</tr>
					<tr>
						<td>
							<input name="clstflag" type="radio" class="normalradio" value="V" <%=clstflag.equalsIgnoreCase("V")?"checked":""%>>
							<%= label.getLabelName(" L_Auto_CustomerList") %>
						</td>
						<td>&nbsp;</td>
					</tr>
					<tr>
						<td>
							<input name="clstflag" type="radio" class="normalradio" value="S" <%=clstflag.equalsIgnoreCase("S")?"checked":""%>>
							<%= label.getLabelName(" L_StandardCustoms") %>
						</td>
						<td>&nbsp;</td>
					</tr>
             	</table>
              </td>
           </tr>
                    
           <tr>
             <td colspan="2">
              <table width="100%" border="1" cellpadding="0" bordercolorlight="#999999" bordercolordark="#FFFFFF" cellspacing="0" align="center">
                 <tr class="deepblue-left">
					<td class="title_center" rowspan="2"><input type="checkbox" name="selectall" onclick="checkAll()" style="border:0"></td>
					<td class="title_center" colspan="3">经销商信息</td>
					<td class="title_center" colspan="4">原始客户信息</td>
					<td class="title_center" rowspan="2">非锁客户信息</td>
					<td class="title_center" rowspan="2">操作</td>
				 </tr>
				 <tr class="deepblue-left">
                   <td class="title_center"><a href="javascript:page_summary('orderby','dealercode')"><%= label.getLabelName("L_Dealer") %></a></td>
                   <td class="title_center"><a href="javascript:page_summary('orderby','sregionname')">所属省</a></td>
                   <td class="title_center"><a href="javascript:page_summary('orderby','scityname')">所属市</a></td>
				   <td class="title_center"><a href="javascript:page_summary('orderby','origincustname')">原始客户</a></td>
                   <td class="title_center">所属省</td>
                   <td class="title_center">所属市</td>
				   <td class="title_center">所属县区</td>
				   <!-- 
                   <td class="title_center"><a href="javascript:page_summary('orderby','custcolcode')">非锁客户</a></td>
                   <td class="title_center">所属省</td>
                   <td class="title_center">所属市</td>
				   <td class="title_center">所属县区</td>
				   -->
                 </tr>
                 <%
                        String strClassType="";
                        int i = 0;
						HashMap onehash = null;
						String str1 = "";
						String str2 = "";
						String str3 = "";
						String str4 = "";
						String str5 = "";
						String str6 = "";
						String str7 = "";
						String str8 = "";
						String str9 = "";
						
						String str10 = "";
						String str11 = "";
						String str12 = "";
                 %>
                 <logic:iterate id="info" collection="<%= totalsummary %>" >
                 <%//show different colours in turns
					 onehash = (HashMap)pageContext.getAttribute("info");
					 str1 = (String)onehash.get("custcolcode");
					 str2 = (String)onehash.get("custcolname");
					 str3 = (String)onehash.get("regioncode");
					 str4 = (String)onehash.get("citycode");
					 str5 = (String)onehash.get("countycode");
					 str6 = (String)onehash.get("regionname");
					 str7 = (String)onehash.get("cityname");
					 str8 = (String)onehash.get("countyname");
					 str9 = (Integer)onehash.get("orgcollateid")+"";
					 
					 str10 = (Integer)onehash.get("orgid")+"";
					 if(str3==null){str3="";str6="";}
					 if(str4==null){str4="";str7="";}
					 if(str5==null){str5="";str8="";}
					 
                     if(i%2 == 1)
                         {
                             strClassType = "td-listrom";
                         }else{
                             strClassType = "none";
                         }
                     i++;
                 %>
                     <tr id="tr<%=i%>" onMouseOver="this.className='tr-over'" onMouseOut="this.className='<%= strClassType %>'" class="<%= strClassType %>">
                         <td class="title_center"><custom:checkbox property="orgcollateid" name="info" changedName="selorgids" style="border:0"/></td>
                         <td>&nbsp;<custom:write name="info" property="dealercode"/>&nbsp;<custom:write name="info" property="dealername"/></td>
                         <td>&nbsp;<custom:write name="info" property="sregionname"/></td>
                         <td>&nbsp;<custom:write name="info" property="scityname"/></td>
                         <td>&nbsp;<custom:write name="info" property="origincustcode"/>&nbsp;<custom:write name="info" property="origincustname"/></td>
                         <td>&nbsp;<custom:write name="info" property="regionname"/></td>
                         <td>&nbsp;<custom:write name="info" property="cityname"/></td>
						 <td>&nbsp;<custom:write name="info" property="countyname"/></td>
                         <td>&nbsp;<custom:write name="info" property="custcolcode"/>&nbsp;<custom:write name="info" property="custcolname"/></td>
                         <!-- 
                         <td>&nbsp;<custom:write name="info" property="custcoregionname"/></td>
                         <td>&nbsp;<custom:write name="info" property="custcocityname"/></td>
						 <td>&nbsp;<custom:write name="info" property="custcocountyname"/></td>
						  -->
						 <td class="title_center"><a onclick="showDiv('submit','<%=str1%>','<%=str2%>','<%=str3%>','<%=str4%>','<%=str5%>','<%=str6%>','<%=str7%>','<%=str8%>','<%=str9%>','<%=str10%>',<%=i%>)"><custom:button label="L_Modify" styleClass="button1" style="width:40px;"/></a></td>
                     </tr>
                  </logic:iterate>
                 <%@ include file="/inc/SummaryAction.inc" %>
               </table>
            </td>
       </tr>
       <tr>
         <td colspan="2">
           <table width="100%" border="0" cellspacing="0" cellpadding="0">
             <tr>
               <td class="summary_top" ></td>
             </tr>
             <tr>
                 <td class="td_center">
					<custom:button label="L_Upload" styleClass="button1" style="width:80px;" onclick="page_upload()" privilegeCode="MB-FSYS01"/>
					<custom:button value="修改下载" styleClass="button1" style="width:80px;" onclick="page_uploadModify()" privilegeCode="MB-FSYS02"/>
					<custom:button value="未对照下载" styleClass="button1" style="width:80px;" onclick="page_uploadModify2()" privilegeCode="MB-TestFS"/>
                 </td>
               </tr>
           </table>
         </td>
     </tr>
     <tr>
         <td>&nbsp;</td>
     </tr>
 </table>
<div id="submit" style="background:white;width:700px;height:125px;border:5px #999999 double;position:absolute;display:none">
    <div id="close" class="deepblue-left" style="width:700px;height:20px;text-align:right;cursor:move;">
	  <img src="<%=contextPath %>/images/closeXXX.jpg" style="cursor:hand" onclick="hidDiv('submit')">
	</div>
    <div style="text-algin:center;height:100px;">
        <table cellspacing="0" cellpadding="0">
            <tr>
                <td>
                    <table border="1" width="694px" cellspacing="0" cellpadding="0" align="center">
                        <tr>
                            <td class="td-text"><%= label.getLabelName("L_NonLockCustomerInfo") + label.getLabelName("L_Colon") %></td>
                            <td>
                                <custom:hidden property="lorgid" />
		           				<custom:hidden property="lorgname" />
		           				<custom:hidden property="newxorgid" />
                                <custom:text property="neworgcode" label="L_RefCode" readonly="true" />
            					<a onclick="javascript:OrgSelectPop();"><custom:button type="3" label="L_Asterisk" imgsrc="flash.gif" border="0"/></a>
            					<custom:text property="neworgname" readonly="true"  label="L_CostomerName"/>
                            </td>
                        <tr>
                        <tr>
                            <td class="td-text"><%= label.getLabelName("L_SCMRole") + label.getLabelName("L_Colon") %></td>
           					<td><custom:selectdic dictType="GlobalPCCode" property="globalpccode" valueCriteria="100" disabled="true" command="notnull" label="L_SCMRole"/></td>
							<td class="td-text"><%= label.getLabelName("L_Province") + label.getLabelName("L_Colon") %></td>
            				<td> 
            					<custom:text property="newregioncode" label="L_Province" size="10" readonly="true"/>
            					<a onclick="javascript:page_selectProvince('newcustomer');"><custom:button type="3" label="L_Asterisk" imgsrc="flash.gif" border="0"/></a>
            					<custom:text property="newregionname" readonly="true" size="20"/>
            				</td>
            				
                        <tr>
                        <tr>
            				<td class="td-text"><%= label.getLabelName("L_City") + label.getLabelName("L_Colon") %></td>
          					<td>
            					<custom:text property="newcitycode" label="L_City" size="10" readonly="true"/>
            					<a onclick="javascript:page_selectCity1('newcustomer','city',1);"><custom:button type="3" label="L_Asterisk" imgsrc="flash.gif" border="0"/></a>
            					<custom:text property="newcityname" readonly="true" size="20"/>
           					</td>
							<td class="td-text"><%= label.getLabelName("L_County") + label.getLabelName("L_Colon") %></td>
            				<td>
              					<custom:text property="newcountycode" label="L_County" size="10" readonly="true"/>
              					<a onclick="javascript:page_selectCity1('newcustomer','county',2);"><custom:button type="3" label="L_Asterisk" imgsrc="flash.gif" border="0"/></a>
              					<custom:text property="newcountyname" readonly="true" size="20"/>
            				</td>  
          				</tr>
                        <tr>
                            <td class="td_center" colspan="4">
							    <custom:hidden property="neworgid"/>
                                <input type="button" name="subbutton" style="width:60px;" value="<%=label.getLabelName("L_Confirm")%>"
                                       onclick="subDiv()"/>
                                <custom:button label="L_Cancel" style="width:60px;" onclick="m=0;hidDiv('submit')"></custom:button>
                            </td>
                        </tr>

                    </table>
                </td>
            </tr>
        </table>
    </div>
</div>
</form>
<iframe name="reloadHandler" style="display:none"></iframe>
<script type="text/javascript">
window.onload = function() {
    var newMask = document.createElement("div");
    newMask.id = "mDiv";
    newMask.style.position = "absolute";
    newMask.style.zIndex = "5000";
    _scrollWidth = Math.max(document.body.scrollWidth, document.documentElement.scrollWidth);
    _scrollHeight = Math.max(document.body.scrollHeight, document.documentElement.scrollHeight);
    newMask.style.width = "100%";
    newMask.style.height = "110%";
    newMask.style.top = "0px";
    newMask.style.left = "0px";
    newMask.style.background = "#33393C";
    newMask.style.filter = "alpha(opacity=40)";
    newMask.style.opacity = "0.40";
    newMask.style.display = 'none';
    newMask.innerHTML = '<iframe style="position:absolute;top:0;left:0;width:100%;height:100%;filter:alpha(opacity=0);"></iframe>'
    document.body.appendChild(newMask);
    document.getElementById("submit").style.zIndex = "5002";
    var objDrag = document.getElementById("close");
    var drag = false;
    var dragX = 0;
    var dragY = 0;
    objDrag.attachEvent("onmousedown", startDrag);
    function startDrag() {
        if (event.button == 1 && event.srcElement.tagName.toUpperCase() == "DIV") {
            event.srcElement.setCapture();
            drag = true;
            dragX = event.clientX;
            dragY = event.clientY;
        }
    };
    objDrag.attachEvent("onmousemove", Drag);
    function Drag() {
        if (drag) {
            var oldwin = event.srcElement.parentNode;
            oldwin.style.left = oldwin.offsetLeft + event.clientX - dragX;
            oldwin.style.top = oldwin.offsetTop + event.clientY - dragY;
            oldwin.style.left = event.clientX - 100;
            oldwin.style.top = event.clientY - 10;
            dragX = event.clientX;
            dragY = event.clientY;
        }
    };
    objDrag.attachEvent("onmouseup", stopDrag);
    function stopDrag() {
        event.srcElement.releaseCapture();
        drag = false;
    };
	
}
document.summaryfrm.location.href = "<%=contextPath%>/masterdata/ogm/OrgSelectCompare.jsp?<%= OvalTools.randomURL() %>";
</script>
 </body>
 </html>


